﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TSCC.WinControl
{
    public partial class ucGridView : UserControl
    {

        public int RowCount
        { 
            get
            { return dataGridView1.RowCount; }
        }

        public int ColumnCount
        {
            get
            {
                return dataGridView1.ColumnCount;
            }
        }

        /// <summary>
        /// 當GridView 中的CellClick & CellEnter 觸發時，把事件傳出來
        /// </summary>
        public event DataGridViewCellEventHandler GVCellEvent = null;

        protected int rowNO = -1;

        public int RowNO
        {
            set
            {
                rowNO = value;
            }
            get
            {
                return rowNO;
            }
        }
        
        public ucGridView()
        {
            InitializeComponent();
        }

        public void SetData(DataTable p_dt)
        {
            dataGridView1.DataSource = p_dt;
        }

        public void NoData()
        {
            dataGridView1.DataSource = null;
        }

        public DataGridViewCell GetDataGridViewCell(int p_columnIndex, int p_rowIndex)
        {
            return dataGridView1[p_columnIndex, p_rowIndex];
        }
       
        private void bindDataGridViewCellEventHandler(object sender, DataGridViewCellEventArgs e)
        {
            if (rowNO != e.RowIndex)
            {
                rowNO = e.RowIndex;
                if (GVCellEvent != null)
                {
                    GVCellEvent(sender, e);
                }
            }
        }
    }
}
